package weekMatch.one_345;

public class LeeCode_02 {
    public static void main(String[] args) {

    }
    private static boolean doesValidArrayExist(int[] derived) {
        int n = derived.length;
        int[] dp1 = new int[n];
        for (int i = 0; i < n - 1; i++) {
            if (dp1[i] == 0){
                dp1[i + 1] = derived[i] == 1 ? 1 : 0;
            }else {
                dp1[i + 1] = derived[i] == 1 ? 0 : 1;
            }
        }
        int flag = dp1[n - 1] == dp1[0] ? 0 : 1;
        if (derived[n - 1] == flag)
            return true;

        dp1 = new int[n];
        dp1[0] = 1;
        for (int i = 0; i < n - 1; i++) {
            if (dp1[i] == 0){
                dp1[i + 1] = derived[i] == 1 ? 1 : 0;
            }else {
                dp1[i + 1] = derived[i] == 1 ? 0 : 1;
            }
        }
        flag = dp1[n - 1] == dp1[0] ? 0 : 1;
        return derived[n - 1] == flag;
    }
}
